﻿using System;
using Pickle.Core.ExtensionMethods;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using System.Web.UI;

namespace UnitTests
{
	/// <summary>
	///This is a test class for ExtensionsTest and is intended
	///to contain all ExtensionsTest Unit Tests
	///</summary>
	[TestClass()]
	public class ExtensionsTest
	{
		private TestContext testContextInstance;

		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		public TestContext TestContext
		{
			get
			{
				return testContextInstance;
			}
			set
			{
				testContextInstance = value;
			}
		}

		/// <summary>
		///A test for Replicate
		///</summary>
		[TestMethod()]
		public void ReplicateTestAppend()
		{
			string source = "Foo";
			string input = "Bar";
			int count = 2;
			ReplicationMode replicationMode = ReplicationMode.Append;
			string expected = "FooBarBar";
			string actual;
			actual = Extensions.Replicate(source, input, count, replicationMode);
			Assert.AreEqual(expected, actual);
		}

		/// <summary>
		///A test for Replicate
		///</summary>
		[TestMethod()]
		public void ReplicateTestPrepend()
		{
			string source = "Foo";
			string input = "Bar";
			int count = 2;
			ReplicationMode replicationMode = ReplicationMode.Prepend;
			string expected = "BarBarFoo";
			string actual;
			actual = Extensions.Replicate(source, input, count, replicationMode);
			Assert.AreEqual(expected, actual);
		}

		/// <summary>
		///A test for Replicate
		///</summary>
		[TestMethod()]
		public void ReplicateTestNull()
		{
			string source = "Foo";
			string input = null;
			int count = 2;
			ReplicationMode replicationMode = ReplicationMode.Append;
			string expected = source;
			string actual;
			actual = Extensions.Replicate(source, input, count, replicationMode);
			Assert.AreEqual(expected, actual);
		}

		/// <summary>
		///A test for Replicate
		///</summary>
		[TestMethod()]
		public void ReplicateTestZero()
		{
			string source = "Foo";
			string input = "Bar";
			int count = 0;
			ReplicationMode replicationMode = ReplicationMode.Append;
			string expected = source;
			string actual;
			actual = Extensions.Replicate(source, input, count, replicationMode);
			Assert.AreEqual(expected, actual);
		}

		/// <summary>
		///A test for SetBit
		///</summary>
		[TestMethod()]
		public void SetBitTest()
		{
			// start with three, bits 1 & 2
			// add four, this will be bits 1, 2 & 4
			// expect 7
			int target = 3;
			int bits = 4;
			bool state = true;
			int expected = 7;
			int actual;
			actual = Extensions.SetBit(target, bits, state);
			Assert.AreEqual(expected, actual);

			// remove four from the target, expect 3
			expected = 3;
			state = false;
			actual = Extensions.SetBit(target, bits, state);
			Assert.AreEqual(expected, actual);

			target = 7;
			actual = Extensions.SetBit(target, bits, state);
			Assert.AreEqual(expected, actual);
		}

		/// <summary>
		/// Test for ReadBit ArgumentException
		/// </summary>
		[TestMethod, ExpectedException(typeof(ArgumentException))]
		public void ReadBitException()
		{
			31.ReadBit(31);
		}

		/// <summary>
		/// Test for SetBit ArgumentException
		/// </summary>
		[TestMethod, ExpectedException(typeof(ArgumentException))]
		public void SetBitException()
		{
			31.SetBit(31, false);
		}

		/// <summary>
		///A test for ReadBit
		///</summary>
		[TestMethod()]
		public void ReadBitTest()
		{
			int target = 32;
			int bit = 1;
			bool expected = false;
			bool actual;
			actual = Extensions.ReadBit(target, bit);
			Assert.AreEqual(expected, actual);

			bit = 32;
			expected = true;
			actual = Extensions.ReadBit(target, bit);
			Assert.AreEqual(expected, actual);
		}

		/// <summary>
		///A test for IsBitUnion
		///</summary>
		[TestMethod()]
		public void IsBitUnionTest()
		{
			int target = 31;
			int bits = 3;
			bool expected = true;
			bool actual;
			actual = Extensions.IsBitUnion(target, bits);
			Assert.AreEqual(expected, actual);

			target = 30;
			expected = false;
			actual = Extensions.IsBitUnion(target, bits);
			Assert.AreEqual(expected, actual);
		}

		/// <summary>
		///A test for IsBit
		///</summary>
		[TestMethod()]
		public void IsBitTest()
		{
			int target = 31;
			bool expected = false;
			bool actual;
			actual = Extensions.IsBit(target);
			Assert.AreEqual(expected, actual);

			target = 32;
			expected = true;

			actual = Extensions.IsBit(target);
			Assert.AreEqual(expected, actual);
		}

		///// <summary>
		/////A test for All
		/////</summary>
		//[TestMethod()]
		//public void AllTest1()
		//{
		//    ControlCollection controls = null; // TODO: Initialize to an appropriate value
		//    IEnumerable<Control> expected = null; // TODO: Initialize to an appropriate value
		//    IEnumerable<Control> actual;
		//    actual = Extensions.All(controls);
		//    Assert.AreEqual(expected, actual);
		//    Assert.Inconclusive("Verify the correctness of this test method.");
		//}

		///// <summary>
		/////A test for All
		/////</summary>
		//[TestMethod()]
		//public void AllTest()
		//{
		//    MenuItemCollection controls = null; // TODO: Initialize to an appropriate value
		//    IEnumerable<MenuItem> expected = null; // TODO: Initialize to an appropriate value
		//    IEnumerable<MenuItem> actual;
		//    actual = Extensions.All(controls);
		//    Assert.AreEqual(expected, actual);
		//    Assert.Inconclusive("Verify the correctness of this test method.");
		//}
	}
}
